﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enlightener.Engine.Structs__Enums___Interfaces;
using Mono.Cecil;

namespace Enlightener.Engine.Deobfuscator.Tasks._1_7
{
    class AntiILDasm : DeobfuscationTask
    {
        public AntiILDasm(AssemblyDefinition asmDef)
            : base(asmDef)
        {
            RoutineDescription = "Remove SuppressILDasm attribute";
        }

        [DeobfuscationPhase(1, "Remove bad attribute")]
        public static bool Phase1()
        {
            var attrib =
                AsmDef.MainModule.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name == "SuppressIldasmAttribute");

            if(attrib == null)
            {
                PhaseError = new PhaseError
                                 {
                                     Level = PhaseError.ErrorLevel.Minor,
                                     Message = "AntiILDasm not activated?"
                                 };
                EmergencyCancel = true;
                return true;
            }

            MarkMember(attrib, AsmDef.MainModule);

            return true;
        }
    }
}
